import { Modal, Form, Input, message } from 'antd'
const FormItem = Form.Item;
import EnterpriseUserSelect from '@/components/EnterpriseUserSelect';
import { save } from '@/services/project/casePlan'


const QaCasePlanAddModal = (props) => {

    const {
        projectId,
        visible,
        onCancel,
        onSaveSuccess,
        dispatch,
        qaDetail
    } = props;

    const [form] = Form.useForm();

    const saveQACasePlan = async () => {
        const values = await form.validateFields()
        console.log(values)
        const data = {
            ...values
        }
        save(projectId, qaDetail.id, data)
            .then((result) => {
                if (result.success) {
                    message.success("保存成功！")
                    onSaveSuccess()
                    form.resetFields()
                }
            })
    }

    return (<Modal
        visible={visible}
        closable
        title={"新增用例执行"}
        onCancel={onCancel}
        onOk={() => {
            saveQACasePlan();
        }}
        destroyOnClose
        okText={"确认"}
        cancelText={"取消"}
    >
        <Form
            form={form}
            labelAlign="right"
            labelCol={{ span: 4 }}
        >
            <FormItem
                label={"名称"}
                name="name"
                rules={[
                    {
                        required: true,
                        message: "请输入名称",
                    },
                ]}
            >
                <Input placeholder={"请输入名称"} maxLength={20} ></Input>
            </FormItem>
            <FormItem
                label={"负责人"}
                name="userId"
                rules={[
                    {
                        required: true,
                        message: "请选择负责人",
                    },
                ]}
            >
                <EnterpriseUserSelect projectId={projectId} ></EnterpriseUserSelect>
            </FormItem>
        </Form>
    </Modal>)
}

export default QaCasePlanAddModal;
